var computeNumber = [];
// 根据实际情况确定几位数
var digitNum = 5;
setComputeNum(getRandomNumber());

// 生成0-99999随机数
function getRandomNumber() {
  return Math.floor(Math.random() * Math.pow(10, digitNum));
};

function setComputeNum(num) {
  num = num.toString()
  if (num.length < digitNum) {
    // 如未满5位数，在前面补位"0"
    num = '0' + num;
    setComputeNum(num);
  } else if (num.length === digitNum) {
    computeNumber = num.split('');
  }
}
for (let i = 0; i < computeNumber.length; i++) {
  // 创建span节点            
  var spanParent = document.createElement("span");
  var spanSon = document.createElement("span");
  // 创建文本节点            
  var node = document.createTextNode("0123456789");
  spanSon.appendChild(node);
  spanParent.append(spanSon);
  spanParent.className = "box-item";
  document.getElementsByClassName("container")[0].append(spanParent);
}

var timer = setInterval(() => {
  setComputeNum(getRandomNumber());
  setTransform();
}, 3000)

// 设置每一位数字的偏移
function setTransform() {
  let boxItem = document.getElementsByClassName("box-item");
  let spans = [];
  for (let i = 0; i < boxItem.length; i++) {
    spans.push(boxItem[i].getElementsByTagName("span")[0]);
  }
  for (let index = 0; index < spans.length; index++) {
    let elem = spans[index];
    elem.style.transform = `translate(-50%, -${computeNumber[index] * 10}%)`;
  }
};